﻿@model ShivamEMR.Model.Domain.PatientDomain.Patient
          
                  <table>
                <tr><td></td><td>
                 </td></tr>

                <tr>
                <td>
                 <table id="patientRepresentatives"  >
                @foreach (var c in Model.Representatives)
                {
                     <tr>
                    <td><span>@c.FullName</span> </td> <td><span>@c.Relation </span> </td>
                      </tr>  
                }   
               </table> 
               </td>
               </tr>           

               <tr><td>
                 @Html.ActionLink("Add More..", "NewRepresentative", "Patient", new { @class = "addRepresentativeLink" })
                 </td>
               </tr>

                </table>


<div id="AddRepresentativeDialog" title="Add Address"></div>
<script type="text/javascript">

    var linkObj;

    function AddressSuccess(data) {
        if (data.Success == true) {
            $('#AddRepresentativeDialog').dialog('close');
        }
        else {
            $("#update-message").html(data.ErrorMessage);
            $("#update-message").show();
        }
    }


    $(function () {
        $(".addRepresentativeLink").button();

        $('#AddRepresentativeDialog').dialog({
            autoOpen: false,
            width: 800,
            resizable: false,
            modal: true,
            buttons: {
                "Add": function () {
                    $("#update-message").html(''); //make sure there is nothing on the message before we continue                         
                    $("#updateRepresentativeForm").submit();
                },
                "Cancel": function () {
                    $(this).dialog("close");
                }
            }
        });

        $(".addRepresentativeLink").click(function () {
            //change the title of the dialog
            linkObj = $(this);
            var dialogDiv = $('#AddRepresentativeDialog');
            var viewUrl = linkObj.attr('href');
            $.get(viewUrl, function (data) {
                dialogDiv.html(data);
                //validation
                var $form = $("#updateRepresentativeForm");
                // Unbind existing validation
                $form.unbind();
                $form.data("validator", null);
                // Check document for changes
                $.validator.unobtrusive.parse(document);
                // Re add validation with changes
                $form.validate($form.data("unobtrusiveValidation").options);
                //open dialog
                dialogDiv.dialog('open');
            });
            return false;
        });

    }); 
</script>
